package ninth.线程操作案例.问题解决2_加入等待与唤醒;

public class Info {
    private String name = "王境泽";
    private String content = "我今天就是饿死也不吃这里的一口饭";
    boolean flag = false;


    public void set(String name, String content) {
        if (!flag) {
            // false 可拿不可做
            try {
                super.wait();// 等待拿6
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            this.setName("张三");
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            this.setContent("爱学习");
            flag = false;
            super.notify();
        }
    }
        public void get () {
            try {
                super.wait();// 等待拿
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            this.get();
            flag = true;
            super.notify();
        }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
